package com.mrobuy.jd.api.category;

import com.jd.open.api.sdk.JdClient;
import com.jd.open.api.sdk.request.supplier.VcItemFeatureFindRequest;
import com.jd.open.api.sdk.response.supplier.VcItemFeatureFindResponse;
import com.mrobuy.jd.api.JosClient;
import com.mrobuy.jdvc.entity.VCFeature;

import java.util.Map;

/**
 *  获取类目下开通品牌信息
 *
 *  jingdong.vc.item.products.find
 *
 *  <url>https://open.jd.com/home/home#/doc/api?apiCateId=86&apiId=1681&apiName=jingdong.vc.item.products.find</url>
 *
 *
 *
 */
public class FeatureFindClient extends JosClient<VCFeature> {

    private VcItemFeatureFindRequest request=new VcItemFeatureFindRequest();

    public FeatureFindClient(JdClient client) {
        super(client);
    }

    @Override
    public VCFeature call() throws Exception {

        VcItemFeatureFindResponse response= client.execute(request);

        if ( response.getJosResultDto().getSuccess() ) {
            VCFeature vcFeature = new VCFeature();
            Map<String, Object> map = response.getJosResultDto().getSingleObj();
            vcFeature.setOtc(map.get("is_otc").toString());
            vcFeature.setPrescription(map.get("is_prescription").toString());
            vcFeature.setAttention(map.get("is_sensitive").toString());
            vcFeature.setGaea(map.get("is_gaea").toString());
            return vcFeature;
        }

        return null;
    }

    public FeatureFindClient setWareId(String ware_id) {
        request.setWareId(ware_id);
        return this;
    }

    public FeatureFindClient setCid3(int cid3) {
        request.setCid3(cid3);
        return this;
    }
}
